﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;


namespace muyu_monitor_plugin
{
    public partial class MainWindow : Window
    {
        private MainWindowViewModel viewModel;

        public MainWindow()
        {
            InitializeComponent();
            viewModel = new MainWindowViewModel();
            DataContext = viewModel;

            // 加载保存的数据
            ConfigData configData = ConfigManager.LoadConfig();
            viewModel.ProductKey = configData.ProductKey;
            viewModel.DeviceName = configData.DeviceName;
            viewModel.Secret = configData.Secret;
            viewModel.MessageConfigItems = configData.MessageConfigItems;

           // MuyuMonitor monitor = new MuyuMonitor();
           // monitor.Start();
        }

        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            // 保存数据
            ConfigData configData = new ConfigData
            {
                ProductKey = viewModel.ProductKey,
                DeviceName = viewModel.DeviceName,
                Secret = viewModel.Secret,
                MessageConfigItems = new ObservableCollection<MessageConfigItem>(viewModel.MessageConfigItems)
            };
            ConfigManager.SaveConfig(configData);
            Close();
        }

        private void AddConfigButton_Click(object sender, RoutedEventArgs e)
        {
            // 添加一个新的配置项到集合
            viewModel.MessageConfigItems.Add(new MessageConfigItem());
        }

        private void RemoveConfigButton_Click(object sender, RoutedEventArgs e)
        {
            // 删除选定的配置项
            if (messageConfigListBox.SelectedItem != null)
            {
                viewModel.MessageConfigItems.Remove((MessageConfigItem)messageConfigListBox.SelectedItem);
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
            
    }
}
